# 1.打开浏览器
from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service(executable_path=r'E:\python\pythonshuju\chromedriver.exe')
driver = webdriver.Chrome(service=service)  #创建浏览器对象
# 2.输入访问地址（URL）
url = r"E:\pyCharm\PyCharm Pro 2024.1\PyCharmshuju\PycharmProjects\UI自动化测试\1\注册实例.html";
driver.get(url)
# 3.页面信息操作
# 用户名
driver.find_element(By.CSS_SELECTOR,"#user").send_keys("admin")
# # 密码
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
# 电话号码
driver.find_element(By.CSS_SELECTOR,"#tel").send_keys("13012345678")
# 电子邮件
driver.find_element(By.CSS_SELECTOR,"#email").send_keys("123@qq.com")
sleep(3)
# 1.获取‘表单综合实例.html’当前窗口句柄
# 目的：判断只要不是当前窗口句柄，就一定是新的窗口句柄
current_handle = driver.current_window_handle
print("综合实例当前窗口句柄：", current_handle)

# 2.点击'注册A页面'链接
driver.find_element(By.PARTIAL_LINK_TEXT,"A网页").click()

# 3. 获取所有窗口句柄
handles = driver.window_handles
print("所有窗口句柄：", handles)
sleep(3)
# 4. 获取注册A页面对应的窗口句柄，并切
# 判断 不是 '当前窗口句柄'
for i in handles:
    if i != current_handle:
        # 切换
        driver.switch_to.window(i)
        # 用户名
        driver.find_element(By.CSS_SELECTOR,"#userA").send_keys("adminA")
        # # 密码
        driver.find_element(By.CSS_SELECTOR,"#passwordA").send_keys("123456")
        # 电话号码
        driver.find_element(By.CSS_SELECTOR,"#telA").send_keys("15011111111")
        # 电子邮件
        driver.find_element(By.CSS_SELECTOR,"#emailA").send_keys("123456@qq.com")

sleep(3)
# 4.关闭/退出浏览器
driver.quit()